import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;

public class ClientSocketThread extends Thread {
    private Socket socket;

    public ClientSocketThread(Socket s) {
        socket = s;
    }

    @Override
    public void run(){
        PrintStream printStream = null;
        try {
            printStream = new PrintStream(socket.getOutputStream());
            long id = Thread.currentThread().getId();
            while(true){
                printStream.println("线程id为："+ id +", 客户端发送消息");
                System.out.println("线程id为："+ id + "客户端内容已发送");
                try {
                    Thread.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null != printStream){
                printStream.close();
            }
            if(null != socket){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
